<% layout('/layouts/default.html', {title: '请假信息管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('请假信息管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<a href="${ctx}/test/leave/form?formType=1" class="btn btn-default btnTool" title="${text('新增请假信息')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${testLeave}" action="${ctx}/test/leave/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('标题')}：</label>
					<div class="control-inline">
						<#form:input path="title" maxlength="100" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('开始时间')}：</label>
					<div class="control-inline">
						<#form:input path="startTime" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('结束时间')}：</label>
					<div class="control-inline">
						<#form:input path="endTime" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('流程实例ID')}：</label>
					<div class="control-inline">
						<#form:input path="instanceId" maxlength="32" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm"><i class="glyphicon glyphicon-search"></i> ${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm isQuick"><i class="glyphicon glyphicon-repeat"></i> ${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script src="${ctxStatic}/activiti.6.0/js/activiti.js"></script>
<script>
//# // 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $('#searchForm'),
	columnModel: [
		{header:'${text("请假类型")}', name:'type', index:'a.type', width:80, align:"center"},
		{header:'${text("标题")}', name:'title', index:'a.title', width:210, align:"left", formatter: function(val, obj, row, act) {
			return '<a href="${ctx}/test/leave/view?tid='+row.id+'" class="btnList" title="${text("请假申请信息")}">'+val+'</a>';
		}},
		{header:'${text("原因")}', name:'reason', index:'a.reason', width:240, align:"left"},
		{header:'${text("起止时间")}', name:'startTime', index:'a.start_time', width:210, align:"center", formatter: function(val, obj, row, act) {
			return row.startTime + ' 至 ' + row.endTime;
		}},
		{header:'${text("请假时长")}', name:'totalTime', index:'a.total_time', width:100, align:"center", formatter: function(val, obj, row, act){
			return formatTotalDateSub(val);
		}},
		{header:'${text("流程实例ID")}', name:'instanceId', index:'a.instance_id', width:80, align:"center"},
		{header:'${text("申请人")}', name:'user.userName', index:'b.user_name', width:90, align:"center"},
		{header:'${text("申请时间")}', name:'applyTime', index:'a.apply_time', width:150, align:"center"},
		{header:'${text("当前任务名称")}', name:'taskName', index:'a.task_name', width:100, align:"center"},
		{header:'${text("操作")}', name:'actions', width:110, formatter: function(val, obj, row, act){
			var actions = [];
			if (row.instanceId) {
				if (row.taskName.indexOf('已结束') === -1) {
					if (row.taskName.indexOf('销假') != -1) {
						actions.push('<a href="javascript:void(0)" onclick="openReportBackModal(\'' + row.taskId + '\',\'' + row.taskName + '\')" title="${text("请假销假")}"><i class="fa fa-share-square-o"></i></a>&nbsp;');
					} else if(row.taskName.indexOf('调整') != -1) {
						actions.push('<a href="javascript:void(0)" onclick="openReportBackModal(\'' + row.taskId + '\',\'' + row.taskName + '\')" title="${text("重新申请")}"><i class="fa fa-refresh"></i></a>&nbsp;');
					} else {
						actions.push('<a href="${ctx}/flow/process/cancelApply?instanceId='+row.instanceId+'" class="btnList" title="${text("撤销申请")}" data-confirm="${text("确认要撤销该申请吗？")}"><i class="icon-action-undo" style="color: #7d7c7a;"></i></a>&nbsp;');
						if (row.suspensionState == 2){
							actions.push('<a href="${ctx}/flow/process/suspendOrActiveApply?instanceId='+row.instanceId+'&suspendState=1" class="btnList" title="${text("激活申请")}" data-confirm="${text("确认要激活该申请吗？")}"><i class="glyphicon glyphicon-ok-circle" style="color: #108c53;"></i></a>&nbsp;');
						} else {
							actions.push('<a href="${ctx}/flow/process/suspendOrActiveApply?instanceId='+row.instanceId+'&suspendState=2" class="btnList" title="${text("挂起申请")}" data-confirm="${text("确认要挂起该申请吗？")}"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
						}
					}
				}
			} else {
				actions.push('<a href="${ctx}/test/leave/form?tid='+row.tid+'" class="btnList" title="${text("编辑请假信息")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/test/leave/delete?tid='+row.tid+'" class="btnList" title="${text("删除请假信息")}" data-confirm="${text("确认要删除该请假信息吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/test/leave/submit?tid='+row.tid+'" class="btnList" title="${text("提交请假申请")}" data-confirm="${text("确认要发起请假申请审批流程吗？")}"><i class="fa fa-check"></i></a>&nbsp;');
			}
			return actions.join('');
		}}
	],
	//# // 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});

function openReportBackModal(taskId,taskName) {
	js.layer.open({
		type: 2,
		maxmin: true,
		shadeClose: true,
		title: taskName,
		area: ['1000px','600px'],
		content: "${ctx}/test/leave/showVerifyDialog?taskId=" + taskId,
		success: function(layero, index){

		}
	});
}
</script>